<?php


namespace App\Api\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ShippingAddress extends Model
{
    use HasFactory;
    use SoftDeletes;
    protected $guarded = [];
    protected $table = 'cmc_shipping_address';


    public static function saveData($data,$where = [])
    {
        if (!empty($where) && is_array($where)){
            return self::query()->where($where)->update($data);
        }
        return self::query()->create($data);
    }
    //获取用户的列表
    static public function getList($phone)
    {
        return ShippingAddress::where('phone',$phone)->get()->toArray();
    }
    //获取购物地址
    static public function getAddr($addressId)
    {
        return ShippingAddress::where('id',$addressId)->get()->toArray()[0];
    }
    //用户收货地址列表
    static public function getUserList($memberId)
    {
        return ShippingAddress::where('member_id',$memberId)->get()->toArray();
    }

    //删除
    public static function delAddress($where)
    {
        return self::where($where)->delete();
    }

    //收货地址详情
    public static function addressInfo($where)
    {
        $info = self::query()->where($where)->first();
        if (!$info) return false;
        return $info->toArray() ;
    }

}
